<!DOCTYPE html>
<html lang="en">


{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">活动</div>
                        </div>
                        <div class="widget-body  am-fr">

                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-6" >
                                <div class="am-form-group" >
                                    <div class="am-btn-toolbar" >
                                        <div class="am-btn-group am-btn-group-xs" >
                                            <a onclick="add_reb()" class="am-btn am-btn-default am-btn-success" ><span class="am-icon-plus" ></span> 新增</a>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="am-u-sm-10">
                                <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                    <thead>
                                    <tr>
                                        <th>返利id</th>
                                        <th>充值金额</th>
                                        <th>追加金额（返利）</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody">
                                    {foreach name="data" key="key" item="value"}

                                        <tr class="gradeX">
                                            <td>{$value.id}
                                                <input type="hidden" name="id" value="{$value.id}">
                                            </td>
                                            <td><input type="number"  name="recharge" value="{$value.recharge}"></td>
                                            <td><input type="number"  name="rebate" value="{$value.rebate}"></td>
                                            <td>
                                                <div class="tpl-table-black-operation">
                                                    <a onclick="roleSubmit(this)">
                                                        <i class="am-icon-pencil"></i> 确认更改
                                                    </a>
                                                    <a onclick="del_button({$value.id});" href="javascript:void(0);" href="javascript:;" class="tpl-table-black-operation-del">
                                                        <i class="am-icon-trash"></i> 删除
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>

                                    {/foreach}
                                    <!-- more data -->
                                    </tbody>
                                </table>
                            </div>
                            <div class="am-u-lg-10 am-cf">

                                <div class="am-fr">
                                    <ul class="am-pagination tpl-pagination">
                                        {$data->render()}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
{include file='Public:script'}

<script>
    //提交
    function roleSubmit(t){
        // var form=document.getElementById("form");

        var id=$(t).parent().parent().parent().find('[name="id"]').val();  //id
        var recharge=$(t).parent().parent().parent().find('[name="recharge"]').val();  //充值金额
        var rebate=$(t).parent().parent().parent().find('[name="rebate"]').val();  //返利金额

        $.post("{:url('rebateadd')}", {id: id,recharge:recharge,rebate:rebate}, function(res) {
            if (res.code != 200) {
                layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                return false;
            }
            layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 1}, function() {
                layer.closeAll('page');
                location.reload();
            });
        });

    }
    //新增按钮
    function add_reb(){
        $html='<tr class="gradeX">\n' +
            '     <td>新增\n' +
            '         <input type="hidden" name="id" value="0">\n' +
            '     </td>\n' +
            '     <td><input type="number" name="recharge" value=""></td>\n' +
            '     <td><input type="number" name="rebate" value=""></td>\n' +
            '     <td>\n' +
            '         <div class="tpl-table-black-operation">\n' +
            '             <a onclick="roleSubmit(this)">\n' +
            '                 <i class="am-icon-pencil"></i> 确认添加\n' +
            '             </a>\n' +
            '             <a onclick="del_but(this);" class="tpl-table-black-operation-del">\n' +
            '                 <i class="am-icon-trash"></i> 删除\n' +
            '             </a>\n' +
            '         </div>\n' +
            '     </td>\n' +
            ' </tr>';

        $('#tbody').append($html);
    }
    //清除新增
    function del_but(t) {
        $(t).parent().parent().parent().remove();
    }
    // 删除按钮
    function del_button(id, className) {
        layer.confirm("确定删除？", {btn: ["确定","取消"], shade: 0.5}, function(){
            // 删除权限组
            $.post("{:url('rebatedel')}", {id: id}, function(res) {
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                    return false;
                }

                layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 1}, function() {
                    layer.closeAll('page');
                    location.reload();
                });
            });
        }, function () {});
    }


</script>
</html>